package com.intct.redis;

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gufg
 * @since 2025-10-16 16:44
 */
public class Demo1 {
    public static void main(String[] args) {

        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        poolConfig.setMaxTotal(100);
        poolConfig.setMaxIdle(100);
        poolConfig.setMinIdle(0);

        // Jedis连接池配置
        JedisPool jedisPool = new JedisPool(poolConfig, "cdh-node", 16379, "default", "Test_090110");

        Jedis jedis = jedisPool.getResource();


//        // Jedis实例
//        Jedis jedis = new Jedis("cdh-node", 16379);

        // 密码
        jedis.auth("Test_090110");

        // 切换数据库
        jedis.select(11);

        // 连接，并执行ping
        System.out.println(jedis.ping());

        // zadd key_name 分数 成员
        Map<String, Double> hashedMap = new HashMap<>();
        hashedMap.put("m10", 10D);
        hashedMap.put("m30", 30D);
        hashedMap.put("m50", 50D);
        hashedMap.put("m20", 20D);
        hashedMap.put("m40", 40D);
        jedis.zadd("zadd_java", hashedMap);

        // 释放资源
        jedis.close();
    }
}
